package com.kaoyaya.delivery.activity;

import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.Bean;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.NoTitle;
import com.googlecode.androidannotations.annotations.ViewById;
import com.googlecode.androidannotations.annotations.sharedpreferences.Pref;
import com.kaoyaya.delivery.data.DataHelper;
import com.kaoyaya.delivery.data.InfoFile_;
import com.kaoyaya.delivery.data.entity.Result;
import com.kaoyaya.util.StringUtil;

@NoTitle
@EActivity(R.layout.activity_feedback)
public class FeedbackActivity extends BaseActivity{
	
	@ViewById TextView tvTitle;
	@ViewById EditText etSuggestion;
	@ViewById Button btnEnsure, btnCancel;
	@Pref InfoFile_ infoFile;
	@Bean DataHelper dataHelper;
	final int IS_FEEDBACK = 0;
	
	@AfterViews
	void initView() {
		app.addActivity(this);
		tvTitle.setText("意见反馈");
		dataHelper.setCallbackHandler(callbackHandler);
	}
	
	@Click
	void btnEnsure() {
		String content = etSuggestion.getText().toString();
		if (StringUtil.isNotTrimBlank(content) && content.length() >4 && content.length() < 513) {
			dataHelper.feekback(IS_FEEDBACK, content);
		} else {
			showToast("内容不能为空，5到512个文字之间！");
		}
	}
	
	@Click
	void btnCancel() {
		finish();
	}
	
	Handler callbackHandler = new Handler() {
		public void handleMessage(Message msg) {
			Object result = msg.obj;
			switch (msg.what) {
				case IS_FEEDBACK:
					Result $result = (Result) result;
					if ($result != null && $result.getResultCode() == 1) {
						showToast($result.getResultMessage());
						finish();
					}
					break;
			}
		}
	};
}
